package pers.lls.hds.sort.bubble;

import java.util.Arrays;

/**
 * 冒泡排序
 *
 * @author lilichai
 */
public class BubbleSort {


    public void bubbleSort(long[] arr) {
        int out, in;
        for (out = arr.length - 1; out > 1; out--) {
            for (in = 0; in < out; in++) {
                if (arr[in] > arr[in + 1]) {
                    long temp = arr[in + 1];
                    arr[in + 1] = arr[in];
                    arr[in] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        BubbleSort sort = new BubbleSort();
        long[] arr = {1,3,5,9,4,2,7};
        sort.bubbleSort(arr);
        Arrays.stream(arr).forEach(d -> System.out.print(" " + d));
    }

}

